package com.cn.demo.springboot.controller;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.demo.springboot.redis.util.IRedisClientUtil;

@Controller
//@Slf4j
@RequestMapping("/redis")
public class RedisController {
	private final static Logger log = LoggerFactory.getLogger(RedisController.class);
	@Autowired
	IRedisClientUtil redisClient;
	
    /**
     * 在redis设置一个string 类型字符
     * @param key
     * @param value
     * @return
     */
    @RequestMapping("setRedisString")
    @ResponseBody
    public Object setRedisString(String key,String value) {
    	redisClient.setString(key, value);
    	return "success";
	}
    
    /**
     * 在redis获取一个string 类型字符
     * @param key
     * @return
     */
    @RequestMapping("getRedisString")
    @ResponseBody
    public Object getRedisString(String key) {
    	return redisClient.getString(key);
	}
    
    /**
     * 在redis设置一个Key-Valie 类型数据
     * @param key
     * @return
     */
    @RequestMapping("setRedis")
    @ResponseBody
    public Object setRedisMap(String key) {
    	HashMap<String,String> hashMap = new HashMap<String,String>();
    	hashMap.put("123", "123");
    	hashMap.put("234", "234");
    	redisClient.setMap(key,hashMap);
    	return "success";
	}
	
    /**
     * 在redis获取一个Key-Valie 类型数据
     * @param key
     * @return
     */
    @RequestMapping("getRedisMap")
    @ResponseBody
    public Object getRedis(String key) {
    	return redisClient.getMap(key);
	}
    


}
